<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="/amigooo/assets/css/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="/amigooo/assets/css/jquery.pnotify.default.css" />
<link type="text/css" rel="stylesheet" href="/amigooo/assets/css/start/start.css" />
<link type="text/css" rel="stylesheet" href="/amigooo/assets/css/menu/menu.css" />
<title>Amigooo!</title>
</head>
<body>
	<div class="row-fluid">
			<div class="navbar navbar-static navbar-custom">
	            <div class="navbar-inner">
					<div class="container" style="width: auto;">
						<a class="brand" href="/amigooo/home/start">Amigooo!</a>
						<ul class="nav pull-right" role="navigation">
							<li class="dropdown">
								<a id="drop1" href="#" role="button" class="dropdown-toggle" data-toggle="dropdown" style="color:white !important;text-shadow: 0 1px 0 #777777 !important;">
									<img id="user-picture" alt="${userSession.user.email}" src="" style="margin-top: -3px !important;"/>
									${userSession.user.name}<b class="caret"></b>
								</a>
								<ul class="dropdown-menu" role="menu" aria-labelledby="drop1">
									<li role="presentation"><a role="menuitem" tabindex="-1" href="#"><i class="icon-wrench"></i> Alterar conta</a></li>
									<li class="divider"></li>
									<li role="presentation"><a role="menuitem" tabindex="-1" href="/amigooo/login/logout"><i class="icon-off"></i> Sair</a></li>
								</ul>
							</li>
						</ul>
					</div>
	            </div>
	            <div class="header">
	            	<a class="title-company" href="/amigooo/start/home" title="${userSession.user.establishment.company}">${userSession.user.establishment.company}</a>
	            </div>
	            <div class="company-logo">
	            	<a href="/amigooo/home/start" title="${userSession.user.establishment.company}"><img id="companyLogo" alt="${userSession.user.establishment.email}" src="" class="img-rounded" /></a>
	            </div>
            </div>
		<div class="fluid12">
			<div class="row-fluid">
				<div class="span2">
					<div class="well sidebar-nav">
						<ul class="nav nav-list">
							<li class="nav-header"><i class="icon-chevron-right"></i> Cardápio</li>
							<li><a href="/amigooo/drinks"><i class="icon-glass"></i> Bedidas</a></li>
							<li><a href="/amigooo/meals"><i class="icon-fire"></i> Refeições</a></li>
							<li><a href="/amigooo/snacks"><i class="icon-leaf"></i> Lanches</a></li>
							<li><a href="/amigooo/specials"><i class="icon-star-empty"></i> Especiais</a></li>
							<li class="active"><a href="/amigooo/sales"><i class="icon-gift"></i> Promoções</a></li>
							<li><a href="/amigooo/others"><i class="icon-tags"></i> Outros</a></li>
							<li class="nav-header"><i class="icon-chevron-right"></i> Opções</li>
							<li><a href="/amigooo/company"><i class="icon-globe"></i> Empresa</a></li>
						</ul>
					</div>
				</div>
				<div class="span10">
					<div class="custom-container">
						<div >
							<fieldset>
								<legend>Promoções</legend>
								<div class="row-fuild">
									<div class="span1">
										<button class="btn btn-primary" type="button" id="add-sale">Adicionar</button>
									</div>
									<div class="span12" style="margin-left: 0px;margin-top: 10px;">
									
										<c:choose>
											<c:when test="${sales != null}">
												<c:forEach items="${sales}" var="item">
													<div class="alert alert-info custom-list">
														<div style="width: 100%;height: 100%;">
															<table>
																<tr>
																	<td style="padding-right: 5px;border-right: 1px solid #e5e5e5;">
																		<img alt="Promoção" src="/amigooo/assets/img/sale.png" style="width: 80px; height: 80px;">
																	</td>
																	<td style="padding-left: 5px;">
							             								<strong>Código:</strong>
							             								<span>${item.code}</span>
							             								<br/>
							             								<strong>Descrição:</strong>
							             								<span>${item.description}</span>
							             								<br/>
							             								<strong>Valor:</strong>
							             								<span>${item.value}</span>
							             								<br/>
							             								<p>
				              												<a class="btn btn-danger btn-mini" href="/amigooo/sales/${item.id}/delete">
				              													<i class="icon-remove"></i>Remover promoção
				              												</a>
				              												<a class="btn btn-mini" id="edit-sale" onclick="requestSale(${item.id})">
				              													<i class="icon-pencil"></i>Editar promoção
				              												</a>
				            											</p>
																	</td>
																</tr>
															</table>
            											</div>
		           					            	</div>
												</c:forEach>
											</c:when>
											<c:when test="${sales == null}">
												<h2>Nenhuma promoção cadastrada</h2>
											</c:when>
										</c:choose>
									</div>
								</div>
							</fieldset>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<div id="sale-modal" class="modal hide fade">
		<form method="post" action="/amigooo/sales/create">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>Adicionar promoção</h3>
			</div>
			
			<div class="modal-body">
				<div class="control-group">
					<label class="control-label">Código</label>
					<div class="controls">
						<div class="input-prepend">
							<span class="add-on"><i class="icon-barcode"></i></span>
							<input id="item.code" name="item.code" type="text" placeholder="Código da promoção" class="input-large" required="">
						</div>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label">Descrição</label>
					<div class="controls">
						<div class="input-prepend">
							<span class="add-on"><i class="icon-bullhorn"></i></span>
							<input id="item.description" name="item.description" type="text" placeholder="Descrição para o cliente" class="input-xlarge" required="">
						</div>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label">Valor</label>
					<div class="controls">
						<div class="input-prepend">
							<span class="add-on"><i class="icon-hand-right"></i></span>
							<input id="item.value" name="item.value" type="text" placeholder="Valor da promoção" class="input-medium" required="">
						</div>
					</div>
				</div>
				
			</div>
			
			<div class="modal-footer">
				<a href="javascript:$('#sale-modal').modal('hide');" class="btn"><i class="icon-remove"></i>Cancelar</a>
				<button class="btn btn-primary" type="submit" id="save-sale"><i class="icon-ok"></i>Adicionar</button>
			</div>
		</form>
	</div>
	
	<div id="sale-edit-modal" class="modal hide fade">
		<form method="post" action="/amigooo/sales/update">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3>Editar promoção</h3>
				<input id="item-id" name="itemed.id" type="hidden" required=""/>
				<input id="item-type" name="itemed.type" type="hidden" required="" value="5"/>
			</div>
			
			<div class="modal-body">
				<div class="control-group">
					<label class="control-label">Código</label>
					<div class="controls">
						<div class="input-prepend">
							<span class="add-on"><i class="icon-barcode"></i></span>
							<input id="item-code" name="itemed.code" type="text" placeholder="Código da promoção" class="input-large" required="">
						</div>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label">Descrição</label>
					<div class="controls">
						<div class="input-prepend">
							<span class="add-on"><i class="icon-bullhorn"></i></span>
							<input id="item-description" name="itemed.description" type="text" placeholder="Descrição para o cliente" class="input-xlarge" required="">
						</div>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label">Valor</label>
					<div class="controls">
						<div class="input-prepend">
							<span class="add-on"><i class="icon-hand-right"></i></span>
							<input id="item-value" name="itemed.value" type="text" placeholder="Valor da promoção" class="input-medium" required="">
						</div>
					</div>
				</div>
				
			</div>
			
			<div class="modal-footer">
				<a href="javascript:$('#sale-edit-modal').modal('hide');" class="btn"><i class="icon-remove"></i>Cancelar</a>
				<button class="btn btn-primary" type="submit" id="edit-sale"><i class="icon-ok"></i>Atualizar</button>
			</div>
		</form>
	</div>
</body>
<script type="text/javascript" src="/amigooo/assets/js/jquery.js"></script>
<script type="text/javascript" src="/amigooo/assets/js/bootstrap.js"></script>
<script type="text/javascript" src="/amigooo/assets/js/jquery.pnotify.js"></script>
<script type="text/javascript" src="/amigooo/assets/js/md5.js"></script>
<script type="text/javascript" src="/amigooo/assets/js/start/script.js"></script>
<script type="text/javascript">
	${error}
	${result}
	
    function requestSale(id) {
		$("#item-id").val("");
		$("#item-code").val("");
		$("#item-description").val("");
		$("#item-value").val("");
		
        $.getJSON('<c:url value="/sales/"/>' + id + "/edit", function (json) {
			$("#item-id").val(json.item.id);
			$("#item-code").val(json.item.code);
			$("#item-description").val(json.item.description);
			$("#item-value").val(json.item.value);
			
			$('#sale-edit-modal').modal('show');
        });
    }
</script>
</html>